﻿CREATE PROCEDURE [dbo].[Subscriber_Delete]
	@email nvarchar(256),
	@activationCode varchar(16) = NULL
AS
BEGIN
	SET @email = LOWER(@email)
	IF NOT EXISTS (SELECT * FROM [dbo].[email_Subscriber] WHERE [Email] = @email)
	BEGIN
		RAISERROR ('EmailNotExist',9,1)
		RETURN
	END
	ELSE IF @activationCode IS NULL OR NOT EXISTS (SELECT * FROM [dbo].[email_Subscriber] WHERE [Email] = @email AND [ActivationCode] = @activationCode)
	BEGIN
		RAISERROR ('IncorrectCode',9,1)
		RETURN
	END
	ELSE
	BEGIN
		DELETE FROM [dbo].[email_Subscriber]
		WHERE [Email] = @email AND [ActivationCode] = @activationCode
	END
END